/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-03-04
*/
package com.rzico.basics.service;

import com.rzico.base.BaseMapper;
import com.rzico.base.impl.BaseServiceImpl;
import com.rzico.basics.entity.Navigation;
import com.rzico.basics.entity.NavigationTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rzico.basics.mapper.NavigationMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * <pre>
 * 设计器业务类
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Service
public class NavigationService extends BaseServiceImpl<Navigation, String> {

    @Autowired
    private NavigationMapper navigationMapper;
    @Autowired
    private NavigationTagService navigationTagService;

    @Override
    public BaseMapper<Navigation, String> getMapper() {
        return navigationMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    public int save(Navigation navigation,Long[] tagIds) {
        int affectCount = super.insertUseGeneratedKeys(navigation);
        if (tagIds!=null) {
            for (Long tagId:tagIds) {
                NavigationTag adTag = new NavigationTag();
                adTag.setNavigations(navigation.getId());
                adTag.setTags(tagId);
                navigationTagService.insert(adTag);
            }
        }

        return affectCount;
    }

    @Transactional(rollbackFor = Exception.class)
    public int update(Navigation navigation,Long[] tagIds) {
        int affectCount = super.updateByPrimaryKeySelective(navigation);
        if (tagIds!=null) {
            NavigationTag adTag = new NavigationTag();

            adTag.setNavigations(navigation.getId());
            navigationTagService.delete(adTag);
            for (Long tagId:tagIds) {
                adTag = new NavigationTag();
                adTag.setNavigations(navigation.getId());
                adTag.setTags(tagId);
                navigationTagService.insert(adTag);
            }
        }
        return affectCount;
    }


}
